package ru.cod.rs.main.units.parts;

import ru.cod.rs.main.enums.Direction;
import ru.cod.rs.main.types.Speed;
import android.view.SurfaceView;

public abstract class Chassis extends AbstractPart {

	protected int speedVal = 5; // defaults
	protected Speed speed;
	protected Integer xDestination;

	// ///////////////////////////////////////////

	public Chassis(SurfaceView cntx, int abc, int ord) {
		super(cntx, abc, ord);

		speed = new Speed(speedVal);

	}

	public Chassis(SurfaceView cntx) {
		super(cntx);
		speed = new Speed(speedVal);
	}

	// ///////////////////////////////////////////
	@Override
	public void update() {
		if ((xDestination != null)
				&& (Math.abs(x - xDestination) >= Math.abs(speed.getValue()))) {
			x += speed.getValue();
		}
	}

	// ///////////////////////////////////////////

	public void moveL() {
		speed.setDirection(Direction.LEFT);
	}

	public void moveR() {
		speed.setDirection(Direction.RIGHT);
	}

	public void stop() {
		speed.setDirection(Direction.NONE);
	}

	// ///////////////////////////////////////////
	@Override
	public void setCoords(int x, int y) {
		setX(x - getWidth() / 2);
		setY(y - getHeight());
	}

	/**
	 * @return the xDestination
	 */
	public int getxDestination() {
		return xDestination;
	}

	/**
	 * @param xDestination
	 *            the xDestination to set
	 */
	public void setxDestination(int xDestination) {
		this.xDestination = xDestination;
	}

}
